﻿using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;


public class TowerInfo_View : IView {
   
    public Image towerPic;
    public Text level;
    public Text attack;
    public Text price;
    public Button btn_upLevel;
    public Button btn_Delete;
    public TowerBase currTower;
	void Awake () {
        btn_upLevel.onClick.AddListener(()=>{
            if(currTower==null) return;
            currTower.UpTower();
            Hide();
        });
        btn_Delete.onClick.AddListener(()=> {
            if (currTower == null) return;
            currTower.SellTower();
            Hide();
        });
    }

    private void Update()
    {
        if (Input.GetMouseButtonDown(1))
        {
            Hide();
        }
    }
    public void UpdateTowerInfo(TowerBase obj)
    {
        if (!obj.HasTower)
        {
            return;
        }
    
        Show();
        currTower = obj;
        level.text ="Level : "+ currTower.GetTower.level;
        attack.text = currTower.GetTower.attack.ToString();
        price.text = currTower.GetTower.price.ToString();
        switch (currTower.GetTower.towerType)
        {
            case TowerType.Archer:
                towerPic.sprite = Resources.Load<Sprite>("TowerPic/role_icon_archer");
                break;
            case TowerType.Mage:
                towerPic.sprite = Resources.Load<Sprite>("TowerPic/role_icon_mage");
                break;
            case TowerType.Turret:
                towerPic.sprite = Resources.Load<Sprite>("TowerPic/role_icon_turret");
                break;
            case TowerType.War:
                towerPic.sprite = Resources.Load<Sprite>("TowerPic/role_icon_warrior");
                break;
        }
    }
    public override void Hide()
    {
        GetComponent<DOTweenAnimation>().DOPlayBackwards();

    }
    public override void Show()
    {
        GetComponent<DOTweenAnimation>().DOPlayForward();

    }
}
